<template>
  <!-- 调单页面 -->
  <div class="app-container">
    <el-form ref="queryForm" :inline="true" :model="queryForm">
      <el-form-item label="买家真实名称" prop="buyUserName">
        <el-input v-model="queryForm.buyUserName" size="small" @change="inputChange(val, 'sale')" placeholder="请输入买家真实名称"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="卖家真实名称" prop="saleUserName">
        <el-input v-model="queryForm.saleUserName" size="small" placeholder="请输入卖家真实名称"
          @change="inputChange(val, 'sale')" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="primary" icon="el-icon-download" :loading="loadingDown" size="mini"
          @click="handleDownLoad">下载需要调单的订单</el-button>
        <el-button type="primary" icon="el-icon-download" :loading="loadingDown" size="mini"
          @click="handleDownLoadAddress">下载发货地址</el-button>
        <el-button type="primary" icon="el-icon-upload" :loading="loadingDown" size="mini"
          @click="showExpress = true">上传快递单号</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>

        <div style="display: inline-block;margin-left: 20px;">
          <span>开仓：</span>
          <el-switch v-model="openGranary" @change="handleOpenGranary" />
        </div>

      </el-form-item>
    </el-form>
    <el-button type="primary" icon="el-icon-s-order" size="mini" @click="adjustmentSwitch(2)">开始调单</el-button>
    <el-button type="primary" icon="el-icon-s-order" size="mini" @click="adjustmentSwitch(1)">{{ buttonName }}</el-button>
    <el-table v-loading="loading" border :data="orderList" style="width: 100%" @sort-change="handleSortChange">
      <el-table-column align="center" label="商品ID" prop="id" width="200" />
      <el-table-column align="center" label="商品名" prop="goodsName" width="300" />
      <el-table-column align="center" label="商品价格" prop="goodsPrice" width="120" />
      <el-table-column align="center" min-width="100" label="买方ID" prop="buyUserId" width="80" />
      <el-table-column align="center" width="150" label="买方姓名" prop="buyUserName" sortable="custom" />
      <el-table-column align="center" label="卖方ID" prop="saleUserId" width="80" />
      <el-table-column align="center" label="卖方姓名" prop="saleUserName" width="100" />
      <el-table-column align="center" label="上架时间" prop="groundingTime" width="180" />
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleSpiltOrder(scope.row)">拆单</el-button>
          <el-button size="mini" @click="handleOrder(scope.row)">重新指定</el-button>
          <el-button size="mini" @click="handleCancelOrder(scope.row)">退回采购区</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total" :total="total" :page.sync="queryForm.pageNum" :limit.sync="queryForm.pageSize"
      @pagination="getList" />

    <el-dialog :visible.sync="showOrderVisible" title="指定用户">
      <el-form ref="formRef" :model="formModel">
        <el-form-item label="买家选择框">
          <el-select v-model="formModel.buyUserId" filterable placeholder="请选择">
            <el-option v-for="item in options" :key="item.mobile" :label="item.mobile + '-' + item.userRealName"
              :value="item.id" />
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showOrderVisible = false">取 消</el-button>
        <el-button type="primary" @click="onConfirm">确定</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="showOrderSplitVisible" title="拆单">

      <el-form ref="formRefs" :model="selectGoods">
        <el-form-item label="商品选择">
          <el-select v-model="formModel.goodsName" @change="changeGoods()" filterable placeholder="请选择">
            <el-option v-for="item in goodsOptions" :key="item.goodsName" :label="item.goodsName"
              :value="item.goodsName" />
          </el-select>
        </el-form-item>
        <el-form-item prop="goodsName" label="商品名称">
          <el-input v-model="formModel.goodsName" placeholder="请选择" disabled />
        </el-form-item>
        <el-form-item prop="goodsMarketPrice" label="市场价">
          <el-input v-model="formModel.goodsMarketPrice" placeholder="请选择" disabled />
        </el-form-item>
        <el-form-item prop="splitCount" label="分配金额">
          <el-input v-model="formModel.splitCount" placeholder="请输入" />
        </el-form-item>
        <!-- <el-form-item prop="number" label="拆分数量" >
      <el-input type="number" v-model="formModel.number" @change="splitNumber" placeholder="请输入数量"/>
    </el-form-item> -->

      </el-form>
      <!-- <el-form>
        <div v-for="item of formModel.number" :key="item">
          <el-form-item :prop="list[item-1].id" label="编号" >
            <el-input :value="(formModel.maxNumber+item)" placeholder="请输入" disabled />
          </el-form-item>
          <el-form-item :prop="list[item-1].splitCount" label="分配金额" :rules="[{ required: true, message: '请输入分配金额' }]">
            <el-input v-model="formModel.list[item-1].splitCount" placeholder="请输入" />
        </el-form-item>
      </div>
    </el-form> -->

      <span slot="footer" class="dialog-footer">
        <el-button @click="showOrderSplitVisible = false">取 消</el-button>
        <el-button type="primary" @click="onSplitConfirm">确定</el-button>
      </span>
    </el-dialog>


    <el-dialog :visible.sync="showExpress" title="上传快递单号">
      <el-form>
        <el-form-item label="上传日期">
          <el-date-picker v-model="orderDate" type="date" @change="selectDate" value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <el-upload :action="excelPath" :headers="headers" :multiple="multiple" :on-success="handleSuccess"
        :on-error="handleError" :data="{ orderDate }" :show-file-list="false" :before-upload="beforeUpload"
        :after-upload="afterUpload" accept=".xlsx, .xls">
        <el-button slot="trigger" size="small" type="primary">选择Excel文件</el-button>
        <!-- <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button> -->
      </el-upload>
      <!-- <div class="error-info">
        
      </div> -->
    </el-dialog>
  </div>
</template>
<script>
import {
  delOrder,
  getOrder,
  refundOrder,
  getTodayData,
  listChannel, getAdjustmentSwitch, splitOrderReq,
  clickShip, getOpenGranary, setOpenGranary, listUser, updateSaleStatus, ListGoodsOptions, getFormerOrderList, adjustmentSwitch, backCartCg, assignCartCg, downloadAdjustmentFormerOrderExcel, exportOrderLogistics
} from '@/api/shop/order'
import { yuan } from '@/utils'
import { excelNameDate } from '@/utils/index'
import { getToken } from '@/utils/auth'

import { excelPath } from '@/api/upload'
export default {
  name: 'AdjOrderList',
  filters: {
    yuan
  },
  data() {
    return {
      orderDate: null,
      multiple: false,
      excelPath,
      headers: { Authorization: 'Bearer ' + getToken() },
      showExpress: false,
      showOrderSplitVisible: false,
      loading: true,
      openGranary: false,
      // 列表总数
      total: 0,
      // 日期范围
      dateRange: [],
      totalBuy: 10000,
      totalSale: 11000,
      totalIncome: 0,
      // 订单状态数据字典
      orderStatusOptions: [],
      payTypeOptions: [
        { name: '微信', value: '1' },
        { name: '支付宝', value: '2' },
        { name: '测试', value: '3' }
      ],
      // 查询参数
      queryForm: {
        pageNum: 1,
        pageSize: 10,
        orderSn: undefined,
        userId: undefined,
        name: undefined,
        saleUserName: undefined,
        buyUserName: undefined
      },
      // 角色列表
      orderList: [],
      orderDialogVisible: false,
      orderDetail: {
        order: {},
        user: {},
        orderGoods: []
      },
      channels: [],
      shipForm: {
        orderId: undefined,
        shipChannel: undefined,
        shipSn: undefined
      },
      shipFormRules: {
        shipChannel: [
          { required: true, message: '发货渠道不能为空', trigger: 'blur' }
        ],
        shipSn: [
          { required: true, message: '发货编号不能为空', trigger: 'blur' }
        ]
      },
      is_adjust: 0,
      shipDialogVisible: false,
      showOrderVisible: false,
      buttonName: '确认调单完成',
      formModel: {
        tableData: [],
        goodsName: '',
        userId: '',
        buyUserName: '',
        list: [],
        number: '',
        splitCount: ''
      },
      options: [],
      loadingDown: false,
      isclick: false,
      selectGoods: {
        maxNumber: 0,
        selectGoods: '',
        splitCount: ''
      },
      record: {},
      goodsOptions: [],
      time: ''
    }
  },
  computed: {

  },
  async created() {
    await this.getOpenGranaryData()
    this.getStatus()
    // this.getOptions()
    this.getList()
    this.getChannel()
  },
  methods: {
    handleDownLoadAddress() {
      if(this.is_adjust!=1){
        return this.$message.error('未完成调单')
      }
      exportOrderLogistics().then(res => {
        const blob = new Blob([res.data], { type: 'application/msword' })// new Blob([res])中不加data就会返回下图中[objece objece]内容（少取一层）
        console.log(blob)
        const dates = excelNameDate()
        const fileName = `今日寄件物流信息${dates}.xls`// 下载文件名称
        const elink = document.createElement('a')
        elink.download = fileName
        elink.style.display = 'none'
        elink.href = URL.createObjectURL(blob)
        document.body.appendChild(elink)
        elink.click()
        URL.revokeObjectURL(elink.href) // 释放URL 对象

      })
    },
    selectDate(val) {
      console.log(val)
      // const select = new Date(val).toLocaleDateString()
      if (val != null) {
        this.$confirm(`是否确认上传 ${val} 的物流信息`).then(res => {
          console.log(res)
          this.orderDate = val
        }).catch(err => {
          this.orderDate = null
        })
      } else {
        console.log('jinlaile')
        this.orderDate = null
      }
      console.log(this.orderDate)
    },
    beforeUpload() {
      if (this.orderDate == null) {
        this.$message.error('时间必选')
        return false
      }
    },
    afterUpload(res) {
      console.log('afterUpload==', res)

      // this.$message.success('上传物流单号成功')
      this.showExpress = false
      this.orderDate = ''

      return true
    },
    handleSuccess(res) {
      console.log('handleSuccess==', res)
      if (res.map.error) {
        return this.$message.error('上传失败，请重新核对数据表')
      }
      this.$message.success('上传物流单号成功')
      this.showExpress = false
      this.orderDate = ''
      return true
    },
    handleError(err) {
      console.log(err)
    },
    getNumber(val) {
      return parseInt(val)
    },
    getId(num) {
      console.log(this.formModel.maxNumber)
      let length = this.formModel.maxNumber.length
      return String(num).padStart(length, '0');
    },
    getName(name, id) {
      if (name.indexOf('组合') == -1) {
        return `${name}（WB${id}）`
      } else {
        return `${name}（TH${id}）`
      }
    },
    splitNumber(val) {
      console.log(val)
      let lsit = []
      val = parseInt(val)
      let now = this.getNumber()
      console.log('now', now)
      for (let i = 0; i < val; i++) {
        console.log(i)
        let params = {}
        params.id = this.getId(now + i + 1)
        lsit.push(params)
      }
      this.$set(this.formModel, 'list', lsit)
      console.log(this.formModel)
    },
    changeGoods() {
      this.goodsOptions.forEach(item => {
        if (item.goodsName === this.formModel.goodsName) {
          this.$set(this.formModel, 'goodsImg', item.goodsImg)
          this.$set(this.formModel, 'maxNumber', item.maxNumber)
          this.$set(this.formModel, 'goodsMarketPrice', item.goodsMarketPrice)
          let now = this.getNumber(item.maxNumber)

          let id = this.getId(now + 1)
          console.log(id, 'id')
          console.log('item.goodsName', item.goodsName)
          let name = this.getName(item.goodsName, id)
          console.log(name)
          this.$set(this.formModel, 'goodsName', name)
        }
      })
    },
    changePeople() {
      this.options.forEach(item => {
        if (item.id == this.formModel.buyerId) {
          this.$set(this.formModel, '')
        }
      })
    },
    async getGoodsOptions() {
      const {
        map: { changeOrder }
      } = await ListGoodsOptions()
      this.goodsOptions = changeOrder
      // console.log(res)
    },
    async onSplitConfirm() {
      if (this.formModel.goodsName == null || this.formModel.goodsName == '' || this.formModel.goodsName == undefined) {
        return this.$message.error('拆单时，必须选择商品')
      }
      if (this.formModel.splitCount > this.record.goodsPrice) {
        return this.$message.error('拆单金额大于原订单金额')
      }
      this.$confirm(
        '是否确认为拆单?',
        '警告',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(async () => {
          const res = await splitOrderReq({ ...this.formModel })
          if(res.code == 200){
            this.$message.success('操作成功')
            // this.formModel = {}
            // this.$refs.formRef.resetFields()
            await this.getList()
            this.$set(this, 'record', {})
            this.$set(this, 'formModel', {})
            this.showOrderSplitVisible = false
          }
        })
    },
    async handleSpiltOrder(record) {
      let status = this.getStauts(record)
      if (status == '已支付待上架') {
        return this.$message.error('当前订单状态已支付未上架，无法拆单')
      }
      await this.getGoodsOptions()

      this.formModel.orderId = record.id
      this.record = record
      this.showOrderSplitVisible = true
    },
    getButtonName() {
      let name = ''
      console.log(this.is_adjust)
      if (this.is_adjust == 2 || this.is_adjust == 0) {
        name = '确认调单完成'
      } else if (this.is_adjust == 1) {
        name = '已完成调单'
      }
      console.log(name)
      //
      // return name
      this.buttonName = name
    },
    inputChange(val, type) {
      console.log(val)
      if (type == 'sale') {

      } else {

      }
    },
    //获取开关仓状态
    async getOpenGranaryData() {
      const res = await getOpenGranary()
      this.openGranary = res.map.isOpen == 1 ? true : false
      console.log(res)
    },
    // 获取买家
    async getOptions(row) {
      const {
        map: { userList }
      } = await listUser()
      userList.forEach((item, index) => {
        if (row.saleUserId == item.id) {
          console.log(index)
          userList.splice(index, 1)
        }
      })
      this.options = userList
      console.log(this.options)
    },
    async onConfirm() {
      this.$refs.formRef.validate(async valid => {
        if (!valid) {
          return
        }
        const userId = this.formModel.userId
        this.options.forEach(item => {
          if (item.id === userId) {
            this.$set(this.formModel, 'buyUserName', item.userRealName)
          }
        })
        console.log(this.formModel)
        // let data ={
        //   // ...this.formModel,
        //   // id:this.
        // }
        this.$set(this.formModel, 'type', 2)
        const res = await assignCartCg(this.formModel)
        console.log(res)
        // await splitOrderReq({ ...this.formModel })
        this.$message.success('操作成功')
        this.formModel = {}
        this.$refs.formRef.resetFields()
        this.getList()
        this.showOrderVisible = false
      })
    },
    async getStatus() {
      const re = await getAdjustmentSwitch()
      this.is_adjust = re.map.is_adjust
      this.getButtonName()
    },
    async handleOrder(record) {
      await this.getOptions(record)
      const re = await getAdjustmentSwitch()
      if (re.map.is_adjust == 1) {
        return this.$message.error('已完成调单，无法指定')
      } else if (re.map.is_adjust == 0) {
        return this.$message.error('还未开始调单，无法指定')
      }
      await this.getList()
      let rows = []
      this.orderList.forEach(item => {
        if (item.id == record.id) {
          rows.push(item)
        }
      })
      if (rows.length == 0) {
        return this.$message.error('当前订单状态已支付，无法重新指定')
      }
      let status = this.getStauts(rows[0])
      if (status === '已支付' || status === '已支付待上架') {
        return this.$message.error('当前订单已支付，无法重新指定')
      }
      this.formModel.id = record.id
      this.showOrderVisible = true
    },
    handleStatus(record) {
      updateSaleStatus({ 'orderId': record.id }).then(res => {
        if (res.code === 200) {
          this.$message.success('操作成功')
        } else {
          this.$message.error('操作失败')
        }
        this.getList()
      })
    },
    async adjustmentSwitch(type) {
      const res = await getOpenGranary()
      if (res.map.isOpen !== 1) {
        return this.$message.error('关仓中，禁止调单！！！')
      }
      console.log(this.isclick)
      // if(this.time!=''){
      //   clearTimeout(this.time)
      //   this.time =''
      // }
      // if(!this.isclick){
      //   this.isclick = true
      // }else{
      //   clearTimeout(this.time)
      //   this.time = setTimeout(()=>{
      //     this.isclick = false
      //     clearTimeout(this.time)
      //   },10000)
      //   return this.$message.error('请勿重复提交')
      // }
      const re = await getAdjustmentSwitch()
      let message = ''
      this.is_adjust = re.map.is_adjust
      if (re.map.is_adjust == 1) {
        this.isclick = false
        return this.$message.error('已完成调单，请勿重复点击')
      } else if (re.map.is_adjust == 0) {
        if (type == 1) {
          this.isclick = false
          return this.$message.error('还未开始调单！')
        }
        message = "是否开始调单（开始调单后，会员无法操作采购区商品）"
      } else {
        if (type == 2) {
          this.isclick = false
          return this.$message.error('已开始调单，请勿重新点击！')
        }
        message = '是否确认已完成调单（确认完成调单后，会员无法对购物车商品操作，且会员交易中金额转至可提现金额）'
      }
      let status = 0
      if (this.is_adjust == 0) {
        status = 2
      } else {
        status = 1
      }

      this.$loading({ text: '数据处理中...' })
      this.$confirm(
        message,
        '警告',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(async (re) => {
        console.log(re)
        const res = await adjustmentSwitch({ status })
        this.is_adjust = status
        if (status == 1) {
          exportOrderLogistics().then(res => {
            const blob = new Blob([res.data], { type: 'application/msword' })// new Blob([res])中不加data就会返回下图中[objece objece]内容（少取一层）
            console.log(blob)
            const dates = excelNameDate()
            const fileName = `今日寄件物流信息${dates}.xls`// 下载文件名称
            const elink = document.createElement('a')
            elink.download = fileName
            elink.style.display = 'none'
            elink.href = URL.createObjectURL(blob)
            document.body.appendChild(elink)
            elink.click()
            URL.revokeObjectURL(elink.href) // 释放URL 对象

          })

        }
        this.$loading().close()

        // clearTimeout(this.time)
        await this.getList()
        // this.time = setTimeout(()=>{
        //   clearTimeout(this.time)
        //   this.isclick = false
        // },100000)
        this.getButtonName()
        if (res.code === 200) {
          this.$message.success('推送成功')
        }
        // this.is_adjust = res.map.is_adjust
      }).catch(() => {
        // this.isclick = false

      })

    },
    submitUpload() {

    },
    getChannel() {
      listChannel().then((response) => {
        this.channels = response.map.data
      })
    },
    handleQuery() {
      this.orderList = []
      this.getList()
    },
    /**
         * 表单重置
         */
    resetQuery() {
      this.$refs.queryForm.resetFields()
      this.dateRange = []
      this.handleQuery()
    },
    async getList() {
      const {
        map: {
          page: { records: data, total },
          buymoneyCount,
          incomeCount,
          selloutMoneyCount
        }
      } = await getFormerOrderList({ ...this.queryForm, timeStr: this.dateRange && this.dateRange.length ? `${this.dateRange[0]},${this.dateRange[1]}` : '' })
      this.total = total
      this.totalBuy = buymoneyCount
      this.totalSale = selloutMoneyCount
      this.totalIncome = incomeCount
      data.forEach(item => {
        if (item.buymoney == null) {
          item.buymoney = 0
        }
        if (item.selloutMoney == null) {
          item.selloutMoney = 0
        }
        if (item.income == null || item.income < 0) {
          item.income = 0
        }
      })
      this.orderList = data
      console.log(this.orderList)
      this.loading = false
    },
    /**
         * 后端排序
         */
    handleSortChange(sort) {
      this.queryForm.sortName = sort.prop
      this.queryForm.sortOrder = sort.order
      this.queryForm.sortStatus = sort.saleStatus
      console.log(sort)
      this.getList()
    },
    async handleDetail(row) {
      const {
        map: { data }
      } = await getOrder(row.id)
      this.orderDetail = data
      this.orderDialogVisible = true
    },
    handleShip(row) {
      this.shipForm = {
        orderId: row.id,
        shipChannel: undefined,
        shipSn: undefined
      }
      this.shipDialogVisible = true
    },
    clickShip(row) {
      this.$refs['shipForm'].validate(async (valid) => {
        if (valid) {
          const { code, msg } = await clickShip(this.shipForm)
          if (code === 200) {
            this.$message.success('发货成功')
            this.shipDialogVisible = false
            this.getList()
          } else {
            this.$message.error(msg)
          }
        }
      })
    },
    handleRefund(row) {
      this.$confirm(
        '是否确认为订单编号为 [' + row.orderSn + '] 的订单退款?',
        '警告',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(async () => {
          await refundOrder(row.id)
          this.$message.success('退款成功')
          await this.getList()
        })
        .catch(function (e) { })
    },
    getStauts(row) {
      if (row.type == 3) {
        return '已下架'

      }
      if (row.status == 1) {
        return '已上架'
      } else {
        if (row.saleStatus == 1 || row.saleStatus == 0 || row.saleStatus == null) {
          return '已加入购物车'
        } else if (row.saleStatus == 3) {
          return '已支付待上架'
        }
      }
    },
    // 退回购物车
    async handleCancelOrder(row) {
      const re = await getAdjustmentSwitch()
      if (re.map.is_adjust == 1) {
        return this.$message.error('已完成调单，无法退回')
      }
      await this.getList()
      let rows = []

      this.orderList.forEach(item => {
        if (item.id == row.id) {
          rows.push(item)
        }
      })
      let status = this.getStauts(rows[0])

      if (status === '已上架') {
        return this.$message.error('当前订单未加入购物车，无需退回')
      } else if (status === '已支付待上架') {
        return this.$message.error('当前订单状态已支付，无法退回')
      }
      this.$confirm(
        '是否确认为商品编号为 [' + row.id + '] 的商品退回购物车?',
        '警告',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(function () {
          return backCartCg({ id: row.id, type: 2 })
          // return refundOrder(row.id)
        })
        .then(res => {
          if (res.code === 200) {
            this.$message.success('退回购物车成功')
            this.getList()
          }
        })
    },
    // 下架购物车
    async handleCancelsOrder(row) {
      const re = await getAdjustmentSwitch()
      if (re.map.is_adjust == 1) {
        return this.$message.error('已完成调单，无法退回')
      }
      this.$confirm(
        '是否确认为商品编号为 [' + row.id + '] 的商品下架?',
        '警告',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(function () {
          return backCartCg({ id: row.id })
          // return refundOrder(row.id)
        })
        .then(res => {
          if (res.code === 200) {
            this.$message.success('退回购物车成功')
            this.getList()
          }
        })
    },
    /**
         * 删除按钮
         */
    async handleDelete(row) {
      const orderId = row.id
      this.$confirm(
        '是否确认删除订单编号为 [' + row.orderSn + '] 的订单吗?',
        '警告',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(function () {
          return delOrder(orderId)
        })
        .then(() => {
          this.getList()
          this.$message.success('删除成功')
        })
        .catch(function (e) { })
    },
    handleDownLoad() {
      this.$confirm(
        '是否下载需要调单的订单',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'info'
        }
      )
        .then(res => {
          downloadAdjustmentFormerOrderExcel().then(res => {
            const blob = new Blob([res.data], { type: 'application/msword' })// new Blob([res])中不加data就会返回下图中[objece objece]内容（少取一层）
            console.log(blob)
            const dates = excelNameDate()
            const fileName = `调单表${dates}.xls`// 下载文件名称
            const elink = document.createElement('a')
            elink.download = fileName
            elink.style.display = 'none'
            elink.href = URL.createObjectURL(blob)
            document.body.appendChild(elink)
            elink.click()
            URL.revokeObjectURL(elink.href) // 释放URL 对象
          })
          // this.loadingDown = true
          console.log(res)
        })
    },
    // 设置开关仓
    async handleOpenGranary(val) {
      console.log(val)
      this.openGranary = val
      await setOpenGranary({ isOpenCgList: val ? '1' : '0' })
      this.getOpenGranaryData()
    }
  }
}
</script>
<style lang="scss" scoped>
.el-image {
  width: 100px;
  height: 100px;
}

.more_btn {
  margin-left: 10px;
}
</style>
